<template>
	<view class="classLayout pageBg">
		<!-- #ifndef MP-TOUTIAO -->
		<custom-nav-bar title="分类"></custom-nav-bar>
		<!-- #endif -->
		
		<view class="classify">
			<theme-item v-for="item in classifyList" 
			:key="item._id"
			:item="item"
			></theme-item>
		</view>
		
		<view class="loadingLayout" v-if="classifyList.length || noData">
			<uni-load-more :status="noData?'noMore':'loading'"></uni-load-more>
		</view>
		
		<view class="safe-area-inset-bottom"></view>
		
	</view>
</template>

<script setup>
import { ref } from 'vue';
import {onShareAppMessage,onShareTimeline,onReachBottom} from "@dcloudio/uni-app"
const classCloudObj = uniCloud.importObject("client-bizhi-classify");
const classifyList = ref([]);
const noData= ref(false);
const queryParams = ref({
	pageSize:15,
	pageNum:1
})

const getClassify =async()=>{
	let {errCode, errMsg, data} = await classCloudObj.list(queryParams.value);
	data = data.map(item => ({...item, updateTime: item.createTime}))
	console.log(data);
	/*let data = [{
		picurl:"https://mp-0cb878b7-99ec-44ea-8246-12b123304b05.cdn.bspapp.com/xxmBizhi/20231010/1696902369329_5036.jpg",
		name:"AI美图",
		updateTime:1730400540670
	},{
		picurl:"https://mp-0cb878b7-99ec-44ea-8246-12b123304b05.cdn.bspapp.com/xxmBizhi/20231010/1696901491940_1839.jpg",
		name:"自然风光",
		updateTime:1729400540670
	}];	*/
	classifyList.value = [...classifyList.value,...data];	
	if(queryParams.value.pageSize > data.length) noData.value = true;
	console.log(data);
}



//触底加载更多
onReachBottom(()=>{
	if(noData.value) return;
	queryParams.value.pageNum++
	getClassify();
})




//分享给好友
onShareAppMessage((e)=>{
	return {
		title:"咸虾米壁纸，精选分类",
		path:"/pages/classify/classify"
	}
})

//分享朋友圈
onShareTimeline(()=>{
	return {
		title:"咸虾米壁纸，精选分类"
	}
})


getClassify();
</script>

<style lang="scss" scoped>
.classify{
	padding:30rpx;
	display: grid;
	grid-template-columns: repeat(3,1fr);
	gap:15rpx;
}
</style>
